// pages/grzl/grzl.js
const app=getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    ming:"",
    nian:"",
    bie:"",
    xiao:"",
    ye:"",
    jingyan:"",
    openid:'',
    grzl:"",
    userInfo: {},
    hasUserInfo: false,
    canIUse: wx.canIUse('button.open-type.getUserInfo')
  },
  getUserInfo: function (e) {
    console.log(e)
    app.globalData.userInfo = e.detail.userInfo
    this.setData({
      userInfo: e.detail.userInfo,
      hasUserInfo: true
    })
  },
  ming(e){
    console.log(e.detail.value)
    this.setData({
      ming:e.detail.value
    })
  },
  nian(e){
    console.log(e.detail.value)
    this.setData({
      nian:e.detail.value
    })
  },
  bie(e){
    console.log(e.detail.value)
    this.setData({
      bie:e.detail.value
    })
  },
  sfzh(e){
    console.log(e.detail.value)
    this.setData({
      sfzh:e.detail.value
    })
  },
  xiao(e){
    console.log(e.detail.value)
    this.setData({
      xiao:e.detail.value
    })
  },
  ye(e){
    console.log(e.detail.value)
    this.setData({
      ye:e.detail.value
    })
  },
  jingyan(e){
    console.log(e.detail.value)
    this.setData({
      jingyan:e.detail.value
    })
  },
 zxjl(e){
  console.log(this.data)
   var ming= this.data.ming;
   var nian=this.data.nian;
   var bie=this.data.bie;
   var xiao=this.data.xiao;
   var ye=this.data.ye;
   var jingyan=this.data.jingyan;
  wx.getStorage({
    key: '222',
    success (res) {
      console.log(res.data)
      wx.request({
        url: app.globalData.yuming+'/grzl',
        method:"POST",
        data: {
         name:ming,
         age:nian,
         sex:bie,
         school:xiao,
         major:ye,
         exp:jingyan,
         openid: res.data,
        },
        success: (res) => {
          console.log(res)
        },
      })
    }
  })
   
 },
  
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    wx.getStorage({
      key: '222',
      success (res) {
        wx.request({
          url: app.globalData.yuming+'/getuserinfo',
          method:"POST",
          data:{
            openid:res.data
          },
          success: (result) => {
            console.log(result)
            that.setData({
              "grzl":result.data
            })
          },
        })
      }
    })
    

    // console.log(this.data.ming)
    wx.getUserInfo({
      lang: '',
      success: function(res) {
        // console.log(res);
      },
      fail: function(res) {},
      complete: function(res) {},
    });
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    if (app.globalData.userInfo) {
      this.setData({
        userInfo: app.globalData.userInfo,
        hasUserInfo: true
      })
    } else if (this.data.canIUse) {
      // 由于 getUserInfo 是网络请求，可能会在 Page.onLoad 之后才返回
      // 所以此处加入 callback 以防止这种情况
      app.userInfoReadyCallback = res => {
        this.setData({
          userInfo: res.userInfo,
          hasUserInfo: true
        })
      }
    } else {
      // 在没有 open-type=getUserInfo 版本的兼容处理
      wx.getUserInfo({
        success: res => {
          app.globalData.userInfo = res.userInfo
          this.setData({
            userInfo: res.userInfo,
            hasUserInfo: true
          })
        }
      })
    }

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})